#!/usr/bin/env python
import pika
import sys
from util.msg_template import MsgTemplateBase


credentials = pika.PlainCredentials('cve_work', 'cve_work')  # mq用户名和密码
# 虚拟队列需要指定参数 virtual_host，如果是默认的可以不填。
connection = pika.BlockingConnection(
    pika.ConnectionParameters(host='118.178.239.213', port=21121, virtual_host='/', credentials=credentials))

# connection = pika.BlockingConnection(
#     pika.ConnectionParameters(host='118.178.239.213', port=21121))
channel = connection.channel()

# channel.exchange_declare(exchange='cve_work_direct', exchange_type='direct', durable=True)

# message = ' '.join(sys.argv[1:]) or "info: Hello World!"
for i in range(200):
    msg = MsgTemplateBase()
    msg.set_key_value("msg_str", "返回的信息：" + str(i))
    message = msg.get_json_dumps()
    channel.basic_publish(exchange='cve_work_direct', routing_key='111', body=message)
    print(" [x] Sent %r" % message)
connection.close()
